package com.pqc.tbk.dao.money;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.pqc.tbk.dao.BaseDaoSupport;
import com.pqc.tbk.entity.money.MoneyInout;
import com.pqc.tbk.utils.Pager;

/**
 * 
 * @author long, create on 2012-8-3 下午8:47:45
 * 
 */
@Repository
public class MoneyInoutDaoImpl extends BaseDaoSupport<MoneyInout> implements
		MoneyInoutDao {

	private final String GETCOUNT = "select count(*) from MoneyInout where 1=1 ";
	private final String CONDITION = "from MoneyInout where 1=1 ";

	@Override
	public Pager<MoneyInout> getPages(final Pager<MoneyInout> pager,
			final String search) {
		final String hql = CONDITION + search;
		final Query query = em.createQuery(hql);
		query.setFirstResult((int) pager.getOffSet());
		query.setMaxResults((int) pager.getPageSize());
		// 查询出结果 组装pager对象
		pager.setContent(query.getResultList());
		return pager;
	}

	@Override
	public Long getCount(final String search) {
		return (Long) em.createQuery(GETCOUNT + search).getSingleResult();
	}

}
